package com.newcapec.org.demo.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.newcapec.org.demo.dao.UserInfoDao;
import com.newcapec.org.demo.entity.UserInfoEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

//转账
//张三100    转给李四10000
//李四1000

//李四钱增加
//张三钱减少(减少失败)
@Service
public class UserInfoService {
    @Resource
    private UserInfoDao userInfoDao;
    public List<UserInfoEntity> selectAll(UserInfoEntity userInfoEntity) {
        return userInfoDao.selectAll(userInfoEntity);
    }



    public HashMap<String,Object> selectByPage(Integer pageNum, Integer pageSize,UserInfoEntity userInfoEntity){
        //此处添加分页配置
        PageHelper.startPage(pageNum,pageSize);

        Page<UserInfoEntity> data = (Page<UserInfoEntity>) userInfoDao.selectAll(userInfoEntity);
        List<UserInfoEntity> datalist = data.getResult();
        Long count = data.getTotal();
        HashMap<String,Object> map = new HashMap<>();
        map.put("count",count);
        map.put("data",datalist);
        return map;
    }


    public UserInfoEntity login(String userName, String userPwd) {
        return userInfoDao.login(userName,userPwd);
    }
    public Boolean insert(UserInfoEntity userInfoEntity){
        return userInfoDao.insertSelective(userInfoEntity);
    }

    public boolean batchDelete(Integer[] userIds) {
        return userInfoDao.batchDelete(userIds);
    }

    public boolean saveBatch(List<UserInfoEntity> list) {
        return userInfoDao.batchInsert(list);
    }

    public UserInfoEntity selectById(Integer userId) {
        return userInfoDao.selectByPrimaryKey(userId);
    }

    public boolean update(UserInfoEntity userInfoEntity) {
        return userInfoDao.updateByPrimaryKeySelective(userInfoEntity);
    }
}
